<!DOCTYPE html >
<html xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>科研人员列表</title>

    <link rel="stylesheet" type="text/css" href="/static/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="/static/fonts/line-icons.css">
    <link href="/static/plugins/datatables/dataTables.bootstrap4.min.css" rel="stylesheet" type="text/css" />
    <link href="/static/plugins/datatables/buttons.bootstrap4.min.css" rel="stylesheet" type="text/css" />
    <link href="/static/plugins/datatables/responsive.bootstrap4.min.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" type="text/css" href="/static/css/main.css">
    <link rel="stylesheet" type="text/css" href="/static/css/responsive.css">

</head>
<body>
<div class="app header-default side-nav-dark">
    <div class="layout">
        <!--顶部栏-->
        <div th:replace="~{/topbar::topbar}">
        </div>
        <!--侧边栏-->
        <div th:replace="~{/sidebar::sidebar}">
        </div>
        <!--主体部分-->
        <div class="page-container">

            <div class="main-content">
                <div class="container-fluid">

                    <div class="breadcrumb-wrapper row">
                        <div class="col-12 col-lg-3 col-md-6">
                            <h4 class="page-title">科研人员</h4>
                        </div>
                        <!--
                        <div class="col-12 col-lg-9 col-md-6">
                            <ol class="breadcrumb float-right">
                                <li><a href="#">Tables</a></li>
                                <li class="active"> / Data Table</li>
                            </ol>
                        </div>
                        -->
                    </div>

                </div>
                <div class="container-fluid">
                    <div class="row">
                        <div class="col-md-11">
                            <div class="card">
                                <div class="card-header border-bottom">
                                    <span class="badge badge-default">科研人员列表</span>
                                    <div class="row">
                                        <div class="col-md-10"></div>
                                        <button type="button" class="btn btn-common" data-toggle="modal" data-target="#addPerson" >新增</button>
                                        &nbsp;
                                        <button type="button" class="btn btn-common"><a href="/admin/user/audit" style="color: white">审核</a></button>
                                    </div>
                                </div>
                                <div class="card-body">
                                    <div class="table-responsive">
                                        <table id="datatable" class="table table-bordered">
                                            <thead>
                                            <tr>
                                                <!--<th>#</th>-->
                                                <th>id</th>
                                                <th>姓名</th>
                                                <!--<th>id</th>-->
                                                <th>角色</th>
                                                <th>账户</th>
                                                <th>审核状态</th>
                                                <th width="240px">操作</th>
                                            </tr>
                                            </thead>
                                            <tbody>
                                            <tr th:each="user:${list}">
                                                <!--<td >1</td>-->
                                                <td th:text="${user.id}">0001</td>
                                                <td th:text="${user.name}">张三</td>
                                                <!--<td th:text="${user.id}">0001</td>-->
                                                <td th:text="${user.role}">1 科研人员</td>
                                                <td th:text="${user.account}">1243214</td>
                                                <td th:text="${user.state}">未审核</td>
                                                <td>
                                                    <a th:href="@{'/admin/user/edit_page?id='+${user.id}}">
                                                    <button type="button" class="btn" data-toggle="modal" data-target="#modifyPerson" >信息修改</button>
                                                    </a>
                                                    <a th:href="@{'/admin/user/modifyPW_page?id='+${user.id}}">
                                                        <button type="button" class="btn" data-toggle="modal" data-target="#modifyPerson" >修改密码</button>
                                                    </a>
                                                    <a >
                                                    <button type="button" class="btn"
                                                    th:onclick="f([[${user.id}]]);">删除</button>
                                                    </a>
                                                </td>
                                            </tr>
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>



                <footer class="content-footer">
                    <div th:replace="~{/footer::footer}"></div>
                </footer>

            </div>

        </div>
    </div>
</div>
<!--新增-->
<div class="modal fade" id="addPerson" tabindex="-1" role="dialog" aria-labelledby="addPerson" aria-hidden="true">
    <div class="modal-dialog" style="width:420px;" role="document">
        <div class="modal-content">
            <div class="modal-header px-4">
                <h5 class="modal-title" id="addPersons">新增人员</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span class="material-icons ">关闭</span>
                </button>
            </div>
            <div class="modal-body p-4">
                <form id="form" method="post" onsubmit="return f2()">
                    <div class="form-group">
                        <label for="addPerson_account">账户</label>
                        <input type="text" class="form-control" id="addPerson_account" placeholder="account" name="account">
                    </div>

                    <div class="form-group">
                        <label for="addPerson_password">密码</label>
                        <input type="password" class="form-control" id="addPerson_password" placeholder="password" name="password">
                    </div>

                    <div class="form-group">
                        <label for="addPerson_name">姓名</label>
                        <input type="text" class="form-control" id="addPerson_name" placeholder="name" name="name">
                    </div>

                    <div class="form-group">
                      <label for="sex">性别</label>
                      <select class="form-control" style="height:30pt;" id="sex" name="sex">
                        <option>男</option>
                        <option>女</option>
                      </select>
                    </div>

                    <div class="form-group">
                        <label for="addPerson_role">职务</label>
                        <select class="form-control" id="addPerson_role" name="role" style="height:30pt;" >
                            <option th:each="role:${roleList}" th:value="${role.nameCh}" th:text="${role.nameCh}">1、科研人员</option>
                        </select>
                    </div>

                    <div class="form-group">
                      <label for="age">年龄</label>
                      <input type="text" class="form-control" id="age" placeholder="age" name="age">
                    </div>
                    <div class="form-group">
                        <label for="org">
                            所属组织机构
                        </label>
                        <select name="org" id = "org">
                            <option th:each="org:${orgList}" th:value="${org.id}" th:text="${org.name}">shuxin</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <label for="ins">
                            所属科研机构
                        </label>
                        <select name="ins" id = "ins">
                            <option th:each="ins:${insList}" th:value="${ins.id}" th:text="${ins.name}">scau</option>
                        </select>
                    </div>
                    <div class="modal-footer px-4">
                        <button type="submit" class="btn btn-common">添加</button>
                        <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

<script src="/static/js/jquery-min.js"></script>
<script src="/static/js/popper.min.js"></script>
<script src="/static/js/bootstrap.min.js"></script>
<script src="/static/js/scripts.js"></script>
<script src="/static/js/jquery.app.js"></script>
<script src="/static/js/main.js"></script>

<script src="/static/plugins/datatables/jquery.dataTables.min.js"></script>
<script src="/static/plugins/datatables/dataTables.bootstrap4.min.js"></script>

<script src="/static/plugins/datatables/dataTables.buttons.min.js"></script>
<script src="/static/plugins/datatables/buttons.bootstrap4.min.js"></script>
<script src="/static/plugins/datatables/jszip.min.js"></script>
<script src="/static/plugins/datatables/pdfmake.min.js"></script>
<script src="/static/plugins/datatables/vfs_fonts.js"></script>
<script src="/static/plugins/datatables/buttons.html5.min.js"></script>
<script src="/static/plugins/datatables/buttons.print.min.js"></script>
<script src="/static/plugins/datatables/buttons.colVis.min.js"></script>

<script src="/static/plugins/datatables/dataTables.responsive.min.js"></script>
<script src="/static/plugins/datatables/responsive.bootstrap4.min.js"></script>

<script src="/static/js/datatables.init.js"></script>

<script type="text/javascript">
    function f(id) {
        $.ajax({
            url:"/admin/user/delete",
            type:"post",
            data:JSON.stringify({
                "id":id
            }),
            contentType:"application/json",
            dataType:"json",
            success:function (result) {
                if (result && result.success) {
                    alert("删除成功");
                    location.reload();
                } else {
                    alert(result.msg);
                }
            }
        });
        return false;
    }

    function f2() {
        var formData = new FormData($('#form')[0]);
        $.ajax({
            url:"/admin/user/add",
            type:"post",
            data:formData,
            processData:false,
            contentType:false,
            success:function (result) {
                if (result && result.success) {
                    alert("提交成功");
                    window.location.href = "/admin/user/list";
                } else {
                    alert(result.msg);
                }
            }
        });
        return false;
    }
</script>
</body>
</html>